<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">版本号</label>
        <el-input v-model="query.versionCode" clearable placeholder="版本号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">版本简介</label>
        <el-input v-model="query.versionInfo" clearable placeholder="版本简介" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">版本名称</label>
        <el-input v-model="query.versionName" clearable placeholder="版本名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-date-picker
          v-model="query.createTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="createTimeStart"
          end-placeholder="createTimeEnd"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="600">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="版本号" prop="versionCode">
            <el-input v-model="form.versionCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="下载地址" prop="downloadUrl">
            <el-input v-model="form.downloadUrl" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="版本简介">
            <el-input v-model="form.versionInfo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="版本名称" prop="versionName">
            <el-input v-model="form.versionName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="版本环境" prop="versionCode">
            <el-radio v-model="form.platfrom" label="1101">安卓</el-radio>
            <el-radio v-model="form.platfrom" label="1102">苹果</el-radio>
          </el-form-item>
          <el-form-item label="是否强制更新" prop="versionName">
            <el-radio v-model="form.forceUpdate" label="true">是</el-radio>
            <el-radio v-model="form.forceUpdate" label="false">否</el-radio>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="versionCode" label="版本号" />
        <el-table-column prop="downloadUrl" label="下载地址" />
        <el-table-column prop="versionInfo" label="版本简介" />
        <el-table-column prop="versionName" label="版本名称" />
        <el-table-column v-permission="['admin','ycVersion:edit','ycVersion:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudYcVersion from '@/api/version/ycVersion'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, versionCode: null, downloadUrl: null, versionInfo: null, versionName: null, createTime: null, platfrom: null }
export default {
  name: 'YcVersion',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'yc_version', url: 'api/ycVersion', sort: 'id,desc', crudMethod: { ...crudYcVersion }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'ycVersion:add'],
        edit: ['admin', 'ycVersion:edit'],
        del: ['admin', 'ycVersion:del']
      },
      rules: {
        versionCode: [
          { required: true, message: '版本号不能为空', trigger: 'blur' }
        ],
        downloadUrl: [
          { required: true, message: '下载地址不能为空', trigger: 'blur' }
        ],
        versionName: [
          { required: true, message: '版本名称不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'versionCode', display_name: '版本号' },
        { key: 'versionInfo', display_name: '版本简介' },
        { key: 'versionName', display_name: '版本名称' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    addV() {

    }
  }
}
</script>

<style scoped>

</style>
